import 'package:flutter/material.dart';

// Tab 页面
class Page extends StatefulWidget {
  const Page({
    Key? key,
    required this.text,
  }) : super(key: key);

  final String text;

  @override
  _PageState createState() => _PageState();
}

class _PageState extends State<Page> {
  @override
  Widget build(BuildContext context) {
    print("build ${widget.text}"); // 用于观察哪些页面被构建了
    return Center(
      child: Text(
        "${widget.text}",
        textScaleFactor: 5,
      ),
    );
  }
}

void main() {
  runApp(const MaterialApp(
    home: Scaffold(
      body: MyPageView(),
    ),
  ));
}

class MyPageView extends StatelessWidget {
  const MyPageView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var children = <Widget>[];
    // 生成 6 个 Tab 页
    for (int i = 0; i < 6; ++i) {
      children.add(Page(text: '$i'));
    }

    return PageView(
      allowImplicitScrolling: true, // 预渲染前后一页
      children: children,
    );
  }
}
